#include "ftppool.hpp"
#include <pthread.h>
#include <string>


using std::string;
using namespace com_oocl_riley;


FtpPool::FtpPool(const string& host,const string& port,const string& usr,const string& pwd,unsigned int maxCon)
    :_host(host),_port(port),_usr(usr),_pwd(pwd),_maxCon(maxCon)
{
    _ftpEnv=FtpEnv::getInstance();
    sem_init(&_sem,0,maxCon);
}
FtpPool::~FtpPool()
{
}

Connection *FtpPool::getConnection()
{
    Connection *con=nullptr;
    sem_wait(&_sem);
    con=curl_easy_init();
    return con;
}

void FtpPool::releaseConnection(Connection *con)
{
    curl_easy_cleanup(con);
    sem_post(&_sem);
}
